home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Macintosh Tracker 1.20 / source / Tracker Client Folder / CMyDocument.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  52.1 KB  |  1,436 lines  |  [TEXT/KAHL]

  1. /* CMyDocument.c */
  2.  
  3. #define compilingmydocument_c
  4.  
  5. #include "CMyDocument.h"
  6. #include "MenuController.h"
  7. #include "CSaveBeforeClosing.h"
  8. #include "Memory.h"
  9. #include "CApplication.h"
  10. #include "File.h"
  11. #include "CSack.h"
  12. #include "Alert.h"
  13. #include "CArray.h"
  14. #include "PortableFile.h"
  15. #include "Error.h"
  16. #include "StandardFile.h"
  17. #include <Sound.h>
  18. #include "CSongList.h"
  19. #include "CRewindButton.h"
  20. #include "CFastForwardButton.h"
  21. #include "CStopButton.h"
  22. #include "CPlayButton.h"
  23. #include "CPauseButton.h"
  24. #include "CSkipToNextButton.h"
  25. #include "LocationConstants.h"
  26. #include "CStaticText.h"
  27. #include "StringUtils.h"
  28. #include "CCheckbox.h"
  29. #include "CNumberEdit.h"
  30. #include "CDefaultStereoOn.h"
  31. #include "CDefaultAntiAlias.h"
  32. #include "CDefaultSamplingRate.h"
  33. #include "CDefaultStereoMix.h"
  34. #include "CDefaultNumRepeats.h"
  35. #include "CDefaultSpeed.h"
  36. #include "CSpecificStereoOn.h"
  37. #include "CSpecificAntiAlias.h"
  38. #include "CSpecificSamplingRate.h"
  39. #include "CSpecificStereoMix.h"
  40. #include "CSpecificNumRepeats.h"
  41. #include "CSpecificSpeed.h"
  42. #include "COverrideStereoOn.h"
  43. #include "COverrideAntiAlias.h"
  44. #include "COverrideSamplingRate.h"
  45. #include "COverrideStereoMix.h"
  46. #include "COverrideNumRepeats.h"
  47. #include "COverrideSpeed.h"
  48. #include "CDividerLine.h"
  49. #include "CMyApplication.h"
  50. #include "CSpecificVolume.h"
  51. #include "CDefaultVolume.h"
  52. #include "COverrideVolume.h"
  53. #include "CAutoNextSong.h"
  54. #include "CRepeat.h"
  55. #include "CAutoStartSongs.h"
  56. #include "CRandomize.h"
  57. #include "CNumOutputBits.h"
  58. #include "Compatibility.h"
  59.  
  60.  
  61. #define UntitledStringID (6592L*65536L + 1)
  62. #define SeparatorID (6592L*65536L + 2)
  63. #define EVENTDELAY (15)
  64.  
  65. #define CouldntSaveSongID (5120L*65536L + 1)
  66. #define ErrorOccurredWhileLoadingID (5120L*65536L + 2)
  67.  
  68. #define MAXRANDOMTRIESBEFOREGIVINGUP (50)
  69.  
  70.  
  71. /* */                CMyDocument::CMyDocument()
  72.     {
  73.         CArray*                SongTemp;
  74.         Handle                Temp;
  75.  
  76.         SongTemp = new CArray;
  77.         SongTemp->IArray(sizeof(SongRec),16);
  78.         ListOfSongs = SongTemp;
  79.  
  80.         RootWindow = NIL;
  81.         EverSaved = False;
  82.         UpToDate = True;
  83.         FileOpenFlag = False;
  84.  
  85.         SamplingRate = 22254;
  86.         StereoOn = False;
  87.         StereoMix = 0;
  88.         AntiAliasing = True;
  89.         Speed = 50;
  90.         NumRepeats = 1;
  91.         Volume = 48;
  92.         AutoNextSong = True;
  93.         Repeat = False;
  94.         AutoStartSongs = True;
  95.         Randomize = False;
  96.         UseSixteenBitMode = False;
  97.  
  98.         Selection = -1;
  99.  
  100.         SongToStart = -1;
  101.         PlayerExists = False;
  102.         PlayNextWhenThisOneStops = False;
  103.         Playing = -1;
  104.  
  105.         GetDateTime((void*)&randSeed);
  106.  
  107.         Temp = GetCString(UntitledStringID);
  108.         Handle2PString(Temp,TheFile.name);
  109.         ReleaseHandle(Temp);
  110.     }
  111.  
  112.  
  113. /* */                CMyDocument::~CMyDocument()
  114.     {
  115.         long                Scan;
  116.         SongRec            Thang;
  117.  
  118.         DeregisterIdler(this);
  119.  
  120.         if (RootWindow != NIL)
  121.             {
  122.                 delete RootWindow;
  123.             }
  124.  
  125.         for (Scan = 0; Scan < ListOfSongs->GetNumElements(); Scan += 1)
  126.             {
  127.                 ListOfSongs->GetElement(Scan,&Thang);
  128.                 ReleaseHandle((Handle)Thang.SongLocation);
  129.             }
  130.         delete ListOfSongs;
  131.  
  132.         if (FileOpenFlag)
  133.             {
  134.                 FCloseFile(FileRef);
  135.             }
  136.     }
  137.  
  138.  
  139. void                CMyDocument::DoNewFile(void)
  140.     {
  141.         MakeNewWindow();
  142.     }
  143.  
  144.  
  145. MyBoolean        CMyDocument::GoAway(void)
  146.     {
  147.         if (!UpToDate && EverSaved)
  148.             {
  149.                 CSaveBeforeClosingWindow*        Saver;
  150.                 MyBoolean                                        Result;
  151.  
  152.                 Saver = new CSaveBeforeClosingWindow;
  153.                 HLock((Handle)this);
  154.                 Result = Saver->SaveBeforeClosing(TheFile.name);
  155.                 HUnlock((Handle)this);
  156.                 switch (Result)
  157.                     {
  158.                         case Yes_Save:
  159.                             if (!SaveFile())
  160.                                 {
  161.                                     return False;
  162.                                 }
  163.                             break;
  164.                         case No_Save:
  165.                             break;
  166.                         case Cancel_Close:
  167.                             return False;
  168.                     }
  169.             }
  170.  
  171.         if (PlayerExists)
  172.             {
  173.                 Application->KillPlayer(OurPlayer);
  174.             }
  175.  
  176.         delete this;
  177.         return True;
  178.     }
  179.  
  180.  
  181. void                CMyDocument::DoPrint(void)
  182.     {
  183.     }
  184.  
  185.  
  186. void                CMyDocument::DoOpenFile(FSSpec* TheSpec)
  187.     {
  188.         short                    LocalRef;
  189.         ulong                    SongCount;
  190.  
  191.         /* reading in all them alias records */
  192.         TheFile = *TheSpec;
  193.         if (FOpenFile(TheSpec,&LocalRef) != noErr)
  194.             {
  195.                 /* error */
  196.             }
  197.         FileOpenFlag = True;
  198.         FileRef = LocalRef;
  199.  
  200.         ResetErrorCheck();
  201.         SamplingRate = (ushort)RShort(LocalRef);
  202.         StereoOn = RChar(LocalRef);
  203.         StereoMix = RShort(LocalRef);
  204.         AntiAliasing = RChar(LocalRef);
  205.         Speed = RShort(LocalRef);
  206.         NumRepeats = RShort(LocalRef);
  207.         Volume = RShort(LocalRef);
  208.         AutoNextSong = RChar(LocalRef);
  209.         Repeat = RChar(LocalRef);
  210.         AutoStartSongs = RChar(LocalRef);
  211.         Randomize = RChar(LocalRef);
  212.  
  213.         SongCount = RShort(LocalRef);
  214.         while (SongCount > 0)
  215.             {
  216.                 ulong                        AliasLength;
  217.                 SongRec                    DaAlias;
  218.                 long                        NewEntry;
  219.  
  220.                 DaAlias.SamplingRateOverrideDefault = RChar(LocalRef);
  221.                 DaAlias.SamplingRate = (ushort)RShort(LocalRef);
  222.                 DaAlias.StereoOnOverrideDefault = RChar(LocalRef);
  223.                 DaAlias.StereoOn = RShort(LocalRef);
  224.                 DaAlias.StereoMixOverrideDefault = RChar(LocalRef);
  225.                 DaAlias.StereoMix = RShort(LocalRef);
  226.                 DaAlias.AntiAliasingOverrideDefault = RChar(LocalRef);
  227.                 DaAlias.AntiAliasing = RShort(LocalRef);
  228.                 DaAlias.SpeedOverrideDefault = RChar(LocalRef);
  229.                 DaAlias.Speed = RShort(LocalRef);
  230.                 DaAlias.NumRepeatsOverrideDefault = RChar(LocalRef);
  231.                 DaAlias.NumRepeats = RShort(LocalRef);
  232.                 DaAlias.VolumeOverrideDefault = RChar(LocalRef);
  233.                 DaAlias.Volume = RShort(LocalRef);
  234.                 DaAlias.Tracker = RChar(LocalRef);
  235.                 FReadBlock(LocalRef,(char*)DaAlias.SongName,SongNameLength);
  236.                 AliasLength = RLong(LocalRef);
  237.                 DaAlias.SongLocation = (AliasRecord**)AllocHandle(AliasLength);
  238.                 HLock((Handle)DaAlias.SongLocation);
  239.                 FReadBlock(LocalRef,(char*)*DaAlias.SongLocation,AliasLength);
  240.                 HUnlock((Handle)DaAlias.SongLocation);
  241.                 DaAlias.PlayedFlag = False;
  242.                 NewEntry = ListOfSongs->AppendElement();
  243.                 ListOfSongs->PutElement(NewEntry,&DaAlias);
  244.                 SongCount -= 1;
  245.             }
  246.         if (ErrorOccurred())
  247.             {
  248.                 AlertError(ErrorOccurredWhileLoadingID,NIL);
  249.             }
  250.         MakeNewWindow();
  251.         SongList->RecalculateScrollBars();
  252.         if ((LastModifiers & controlKey) == 0)
  253.             {
  254.                 /* if they were NOT holding down the control key, then we want */
  255.                 /* to see if they are now.  Otherwise, we don't want to clear it. */
  256.                 RelinquishCPU();
  257.             }
  258.         if (AutoStartSongs && ((LastModifiers & controlKey) == 0))
  259.             {
  260.                 /* if they want to autostart songs upon opening the document AND */
  261.                 /* they didn't hold down the command key while selecting "open" */
  262.                 /* (or starting the program) then we can do it. */
  263.                 if (Randomize)
  264.                     {
  265.                         StartRandomSong();
  266.                     }
  267.                  else
  268.                     {
  269.                         StartThisSong(0);
  270.                     }
  271.             }
  272.         EverSaved = True;
  273.     }
  274.  
  275.  
  276. MyBoolean        CMyDocument::SaveFile(void)
  277.     {
  278.         if (EverSaved)
  279.             {
  280.                 WriteData();
  281.                 return True;
  282.             }
  283.          else
  284.             {
  285.                 return SaveFileAs();
  286.             }
  287.     }
  288.  
  289.  
  290. MyBoolean        CMyDocument::SaveFileAs(void)
  291.     {
  292.         FSSpec            NewInfo;
  293.         MyBoolean        Result;
  294.         MyBoolean        Replacing;
  295.  
  296.         HLock((Handle)this);
  297.         Result = FPutFile(TheFile.name,&NewInfo,&Replacing);
  298.         if (Result)
  299.             {
  300.                 if (Replacing)
  301.                     {
  302.                         FDeleteFile(&NewInfo);
  303.                     }
  304.                 TheFile = NewInfo;
  305.                 FCreate(&NewInfo,CREATORCODE,FILETYPE1);
  306.                 FOpenFile(&NewInfo,&FileRef);
  307.                 FileOpenFlag = True;
  308.                 WriteData();
  309.                 EverSaved = True;
  310.                 SetWTitle(RootWindow->MyGrafPtr,TheFile.name);
  311.             }
  312.         HUnlock((Handle)this);
  313.         return Result;
  314.     }
  315.  
  316.  
  317. void                CMyDocument::WriteData(void)
  318.     {
  319.         ulong                    SongCount;
  320.         ulong                    SongScan;
  321.         long                    FilePosTemp;
  322.  
  323.         ERROR(!FileOpenFlag,PRERR(ForceAbort,"CMyDocument::WriteData called when "
  324.             "no file was open for writing."));
  325.  
  326.         SpecificSamplingRateBox->StoreValue();
  327.         SpecificStereoMixBox->StoreValue();
  328.         SpecificNumRepeatsBox->StoreValue();
  329.         SpecificSpeedBox->StoreValue();
  330.         SpecificVolumeBox->StoreValue();
  331.         DefaultSamplingRateBox->StoreValue();
  332.         DefaultStereoMixBox->StoreValue();
  333.         DefaultNumRepeatsBox->StoreValue();
  334.         DefaultSpeedBox->StoreValue();
  335.         DefaultVolumeBox->StoreValue();
  336.  
  337.         ResetErrorCheck();
  338.         FSetFilePos(FileRef,0);
  339.  
  340.         WShort(FileRef,SamplingRate);
  341.         WChar(FileRef,StereoOn);
  342.         WShort(FileRef,StereoMix);
  343.         WChar(FileRef,AntiAliasing);
  344.         WShort(FileRef,Speed);
  345.         WShort(FileRef,NumRepeats);
  346.         WShort(FileRef,Volume);
  347.         WChar(FileRef,AutoNextSong);
  348.         WChar(FileRef,Repeat);
  349.         WChar(FileRef,AutoStartSongs);
  350.         WChar(FileRef,Randomize);
  351.  
  352.         SongCount = ListOfSongs->GetNumElements();
  353.         WShort(FileRef,SongCount);
  354.         for (SongScan = 0; SongScan < SongCount; SongScan += 1)
  355.             {
  356.                 SongRec            Song;
  357.                 ulong                AliasSize;
  358.  
  359.                 ListOfSongs->GetElement(SongScan,&Song);
  360.                 WChar(FileRef,Song.SamplingRateOverrideDefault);
  361.                 WShort(FileRef,Song.SamplingRate);
  362.                 WChar(FileRef,Song.StereoOnOverrideDefault);
  363.                 WShort(FileRef,Song.StereoOn);
  364.                 WChar(FileRef,Song.StereoMixOverrideDefault);
  365.                 WShort(FileRef,Song.StereoMix);
  366.                 WChar(FileRef,Song.AntiAliasingOverrideDefault);
  367.                 WShort(FileRef,Song.AntiAliasing);
  368.                 WChar(FileRef,Song.SpeedOverrideDefault);
  369.                 WShort(FileRef,Song.Speed);
  370.                 WChar(FileRef,Song.NumRepeatsOverrideDefault);
  371.                 WShort(FileRef,Song.NumRepeats);
  372.                 WChar(FileRef,Song.VolumeOverrideDefault);
  373.                 WShort(FileRef,Song.Volume);
  374.                 WChar(FileRef,Song.Tracker);
  375.                 FWriteBlock(FileRef,(char*)Song.SongName,SongNameLength);
  376.                 AliasSize = HandleSize((Handle)Song.SongLocation);
  377.                 WLong(FileRef,AliasSize);
  378.                 HLock((Handle)Song.SongLocation);
  379.                 FWriteBlock(FileRef,(char*)*Song.SongLocation,AliasSize);
  380.                 HUnlock((Handle)Song.SongLocation);
  381.             }
  382.         FGetFilePos(FileRef,&FilePosTemp);
  383.         FSetEOF(FileRef,FilePosTemp);
  384.         if (ErrorOccurred())
  385.             {
  386.                 AlertError(CouldntSaveSongID,NIL);
  387.             }
  388.          else
  389.             {
  390.                 UpToDate = True;
  391.             }
  392.     }
  393.  
  394.  
  395. void                CMyDocument::AddSong(FSSpec* TheSpec)
  396.     {
  397.         AliasRecord**            SystemAlias;
  398.         SongRec                        MyAlias;
  399.         long                            IndexToStoreAt;
  400.         OSErr                            Error;
  401.         short                            Scan;
  402.  
  403.         for (Scan = 0; Scan < sizeof(MyAlias); Scan += 1)
  404.             {
  405.                 ((char*)&MyAlias)[Scan] = 0;
  406.             }
  407.         MyAlias.SamplingRateOverrideDefault = False;
  408.         MyAlias.StereoOnOverrideDefault = False;
  409.         MyAlias.StereoMixOverrideDefault = False;
  410.         MyAlias.AntiAliasingOverrideDefault = False;
  411.         MyAlias.SpeedOverrideDefault = False;
  412.         MyAlias.NumRepeatsOverrideDefault = False;
  413.         MyAlias.VolumeOverrideDefault = False;
  414.         MyAlias.SamplingRate = SamplingRate;
  415.         MyAlias.StereoOn = StereoOn;
  416.         MyAlias.StereoMix = StereoMix;
  417.         MyAlias.AntiAliasing = AntiAliasing;
  418.         MyAlias.Speed = Speed;
  419.         MyAlias.NumRepeats = NumRepeats;
  420.         MyAlias.Volume = Volume;
  421.         MyAlias.Tracker = False;
  422.         MemCpy((char*)MyAlias.SongName,(char*)TheSpec->name,TheSpec->name[0] + 1);
  423.         if (MyAlias.SongName[0] > SongNameLength - 1)
  424.             {
  425.                 MyAlias.SongName[0] = SongNameLength - 1;
  426.             }
  427.         Error = NewAlias(NIL,TheSpec,&SystemAlias);
  428.         MyAlias.SongLocation = (AliasRecord**)DupSysHandle((Handle)SystemAlias);
  429.         DisposHandle((Handle)SystemAlias);
  430.         MyAlias.PlayedFlag = False;
  431.         IndexToStoreAt = ListOfSongs->AppendElement();
  432.         ListOfSongs->PutElement(IndexToStoreAt,&MyAlias);
  433.         EXECUTE(ListOfSongs->GetElement(IndexToStoreAt,&MyAlias);)
  434.         SongList->Redraw(IndexToStoreAt,IndexToStoreAt);
  435.         SongList->RecalculateScrollBars();
  436.         if ((LastModifiers & controlKey) == 0)
  437.             {
  438.                 /* if they were NOT holding down the control key, then we want */
  439.                 /* to see if they are now.  Otherwise, we don't want to clear it. */
  440.                 RelinquishCPU();
  441.             }
  442.         if ((Playing == -1) && (SongToStart == -1) && AutoStartSongs
  443.             && ((LastModifiers & controlKey) == 0))
  444.             {
  445.                 StartThisSong(IndexToStoreAt);
  446.             }
  447.         UpToDate = False;
  448.     }
  449.  
  450.  
  451. void                CMyDocument::CancelCurrentSong(void)
  452.     {
  453.         if (PlayerExists)
  454.             {
  455.                 Application->KillPlayer(OurPlayer);
  456.                 PlayerState = PlayerDying;
  457.             }
  458.         PlayNextWhenThisOneStops = False;
  459.     }
  460.  
  461.  
  462. void                CMyDocument::StartThisSong(long SongIndex)
  463.     {
  464.         SongRec                    Temp;
  465.  
  466.         if (Playing != -1)
  467.             {
  468.                 CancelCurrentSong();
  469.             }
  470.         if ((SongIndex >= 0) && (SongIndex < ListOfSongs->GetNumElements()))
  471.             {
  472.                 RegisterIdler(this,EVENTDELAY);
  473.                 SongToStart = SongIndex;
  474.                 ListOfSongs->GetElement(SongIndex,&Temp);
  475.                 Temp.PlayedFlag = True;
  476.                 ListOfSongs->PutElement(SongIndex,&Temp);
  477.             }
  478.         PlayNextWhenThisOneStops = AutoNextSong;
  479.     }
  480.  
  481.  
  482. void                CMyDocument::RemoveSongFromList(long SongIndex)
  483.     {
  484.         SongRec                Temp;
  485.  
  486.         if ((SongIndex >= 0) && (SongIndex < ListOfSongs->GetNumElements()))
  487.             {
  488.                 if (SongIndex == Playing)
  489.                     {
  490.                         CancelCurrentSong();
  491.                     }
  492.                 if (SongIndex < Playing)
  493.                     {
  494.                         Playing -= 1;
  495.                     }
  496.                 UpToDate = False;
  497.                 ListOfSongs->GetElement(SongIndex,&Temp);
  498.                 ReleaseHandle((Handle)Temp.SongLocation);
  499.                 ListOfSongs->DeleteElement(SongIndex);
  500.                 SongList->Redraw(SongIndex,ListOfSongs->GetNumElements());
  501.             }
  502.     }
  503.  
  504.  
  505. void                CMyDocument::MakeNewWindow(void)
  506.     {
  507.         CWindow*                        Window;
  508.         LongPoint                        Start;
  509.         LongPoint                        Extent;
  510.         CStaticText*                StaticText;
  511.         CPlayButton*                PlayButton;
  512.         CDividerLine*                DividerLine;
  513.  
  514.  
  515.         MoveHHi((Handle)this);
  516.         HLock((Handle)this);
  517.  
  518.  
  519.         Window = new CWindow;
  520.         GetRect(WindowLocsID,&Start,&Extent);
  521.         Start = CenterRect(Extent,MainScreenSize());
  522.         Window->IWindow(Start,Extent,ModelessWindow,NoGrowable,NoZoomable);
  523.         RootWindow = Window;
  524.         SetWTitle(Window->MyGrafPtr,TheFile.name);
  525.  
  526.  
  527.         SongList = new CSongList;
  528.         SongList->ISongList(this,Window);
  529.  
  530.  
  531.         RewindButton = new CRewindButton;
  532.         RewindButton->IRewindButton(this,Window);
  533.  
  534.         StopButton = new CStopButton;
  535.         StopButton->IStopButton(this,Window);
  536.  
  537.         PlayButton = new CPlayButton;
  538.         PlayButton->IPlayButton(this,Window);
  539.         PausePlayButton = PlayButton;
  540.  
  541.         FastForwardButton = new CFastForwardButton;
  542.         FastForwardButton->IFastForwardButton(this,Window);
  543.  
  544.         SkipToNextButton = new CSkipToNextButton;
  545.         SkipToNextButton->ISkipToNextButton(this,Window);
  546.  
  547.  
  548.         StaticText = new CStaticText;
  549.         GetRect(DefaultSettingsID,&Start,&Extent);
  550.         StaticText->IStaticText(Start,Extent,GetCString(DefaultSettingsID),
  551.             applFont,9,Window,Window,JustifyLeft);
  552.  
  553.         StaticText = new CStaticText;
  554.         GetRect(DefaultFrequencyID,&Start,&Extent);
  555.         StaticText->IStaticText(Start,Extent,GetCString(DefaultFrequencyID),
  556.             applFont,9,Window,Window,JustifyLeft);
  557.  
  558.         StaticText = new CStaticText;
  559.         GetRect(DefaultSpeedID,&Start,&Extent);
  560.         StaticText->IStaticText(Start,Extent,GetCString(DefaultSpeedID),
  561.             applFont,9,Window,Window,JustifyLeft);
  562.  
  563.         StaticText = new CStaticText;
  564.         GetRect(DefaultRepeatsID,&Start,&Extent);
  565.         StaticText->IStaticText(Start,Extent,GetCString(DefaultRepeatsID),
  566.             applFont,9,Window,Window,JustifyLeft);
  567.  
  568.         StaticText = new CStaticText;
  569.         GetRect(DefaultMixID,&Start,&Extent);
  570.         StaticText->IStaticText(Start,Extent,GetCString(DefaultMixID),
  571.             applFont,9,Window,Window,JustifyLeft);
  572.  
  573.         StaticText = new CStaticText;
  574.         GetRect(DefaultVolumeID,&Start,&Extent);
  575.         StaticText->IStaticText(Start,Extent,GetCString(DefaultVolumeID),
  576.             applFont,9,Window,Window,JustifyLeft);
  577.  
  578.         SpecificSamplingRateText = new CStaticText;
  579.         GetRect(SpecificFrequencyID,&Start,&Extent);
  580.         SpecificSamplingRateText->IStaticText(Start,Extent,GetCString(SpecificFrequencyID),
  581.             applFont,9,Window,Window,JustifyLeft);
  582.  
  583.         SpecificSpeedText = new CStaticText;
  584.         GetRect(SpecificSpeedID,&Start,&Extent);
  585.         SpecificSpeedText->IStaticText(Start,Extent,GetCString(SpecificSpeedID),
  586.             applFont,9,Window,Window,JustifyLeft);
  587.  
  588.         SpecificNumRepeatsText = new CStaticText;
  589.         GetRect(SpecificRepeatsID,&Start,&Extent);
  590.         SpecificNumRepeatsText->IStaticText(Start,Extent,GetCString(SpecificRepeatsID),
  591.             applFont,9,Window,Window,JustifyLeft);
  592.  
  593.         SpecificStereoMixText = new CStaticText;
  594.         GetRect(SpecificMixID,&Start,&Extent);
  595.         SpecificStereoMixText->IStaticText(Start,Extent,GetCString(SpecificMixID),
  596.             applFont,9,Window,Window,JustifyLeft);
  597.  
  598.         SpecificVolumeText = new CStaticText;
  599.         GetRect(SpecificVolumeID,&Start,&Extent);
  600.         SpecificVolumeText->IStaticText(Start,Extent,GetCString(SpecificVolumeID),
  601.             applFont,9,Window,Window,JustifyLeft);
  602.  
  603.         AutoNextSongBox = new CAutoNextSong;
  604.         AutoNextSongBox->IAutoNextSong(this,Window);
  605.  
  606.         RepeatBox = new CRepeat;
  607.         RepeatBox->IRepeat(this,Window);
  608.  
  609.         AutoStartSongsBox = new CAutoStartSongs;
  610.         AutoStartSongsBox->IAutoStartSongs(this,Window);
  611.  
  612.         RandomizeBox = new CRandomize;
  613.         RandomizeBox->IRandomize(this,Window);
  614.  
  615.         DividerLine = new CDividerLine;
  616.         DividerLine->IDividerLine(Window);
  617.  
  618.  
  619.         DefaultStereoOnBox = new CDefaultStereoOn;
  620.         DefaultStereoOnBox->IDefaultStereoOn(this,Window);
  621.  
  622.         DefaultAntiAliasingBox = new CDefaultAntiAliasing;
  623.         DefaultAntiAliasingBox->IDefaultAntiAliasing(this,Window);
  624.  
  625.         DefaultVolumeBox = new CDefaultVolume;
  626.         DefaultVolumeBox->IDefaultVolume(this,Window);
  627.         DefaultVolumeBox->SetValue(Volume);
  628.  
  629.         DefaultSamplingRateBox = new CDefaultSamplingRate;
  630.         DefaultSamplingRateBox->IDefaultSamplingRate(this,Window);
  631.         DefaultSamplingRateBox->SetValue(SamplingRate);
  632.  
  633.         DefaultSpeedBox = new CDefaultSpeed;
  634.         DefaultSpeedBox->IDefaultSpeed(this,Window);
  635.         DefaultSpeedBox->SetValue(Speed);
  636.  
  637.         DefaultNumRepeatsBox = new CDefaultNumRepeats;
  638.         DefaultNumRepeatsBox->IDefaultNumRepeats(this,Window);
  639.         DefaultNumRepeatsBox->SetValue(NumRepeats);
  640.  
  641.         DefaultStereoMixBox = new CDefaultStereoMix;
  642.         DefaultStereoMixBox->IDefaultStereoMix(this,Window);
  643. = -1)
  644.             {
  645.                 return;
  646.             }
  647.  
  648.         UpToDate = False;
  649.         ListOfSongs->GetElement(Selection,&Temp);
  650.         Temp.StereoMixOverrideDefault = Flag;
  651.         if (Flag)
  652.             {
  653.                 Temp.StereoMix = StereoMix;
  654.                 SpecificStereoMixBox->DoEnable();
  655.                 SpecificStereoMixText->DoEnable();
  656.                 if (SpecificStereoMixBox->GetValue() != Temp.StereoMix)
  657.                     {
  658.                         SpecificStereoMixBox->SetValue(Temp.StereoMix);
  659.                     }
  660.             }
  661.          else
  662.             {
  663.                 SpecificStereoMixBox->DoDisable();
  664.                 SpecificStereoMixText->DoDisable();
  665.                 if (Selection == Playing)
  666.                     {
  667.                         SendMessage((short)StereoMix,keyStereoMix);
  668.                     }
  669.             }
  670.         ListOfSongs->PutElement(Selection,&Temp);
  671.     }
  672.  
  673.  
  674. void                CMyDocument::SetOverrideNumRepeats(MyBoolean Flag)
  675.     {
  676.         SongRec                Temp;
  677.  
  678.         if (Selection == -1)
  679.             {
  680.                 return;
  681.             }
  682.  
  683.         UpToDate = False;
  684.         ListOfSongs->GetElement(Selection,&Temp);
  685.         Temp.NumRepeatsOverrideDefault = Flag;
  686.         if (Flag)
  687.             {
  688.                 Temp.NumRepeats = NumRepeats;
  689.                 SpecificNumRepeatsBox->DoEnable();
  690.                 SpecificNumRepeatsText->DoEnable();
  691.                 if (SpecificNumRepeatsBox->GetValue() != Temp.NumRepeats)
  692.                     {
  693.                         SpecificNumRepeatsBox->SetValue(Temp.NumRepeats);
  694.                     }
  695.             }
  696.          else
  697.             {
  698.                 SpecificNumRepeatsBox->DoDisable();
  699.                 SpecificNumRepeatsText->DoDisable();
  700.                 if (Selection == Playing)
  701.                     {
  702.                         SendMessage((short)NumRepeats,keyNumRepeats);
  703.                     }
  704.             }
  705.         ListOfSongs->PutElement(Selection,&Temp);
  706.     }
  707.  
  708.  
  709. void                CMyDocument::SetOverrideSpeed(MyBoolean Flag)
  710.     {
  711.         SongRec                Temp;
  712.  
  713.         if (Selection == -1)
  714.             {
  715.                 return;
  716.             }
  717.  
  718.         UpToDate = False;
  719.         ListOfSongs->GetElement(Selection,&Temp);
  720.         Temp.SpeedOverrideDefault = Flag;
  721.         if (Flag)
  722.             {
  723.                 Temp.Speed = Speed;
  724.                 SpecificSpeedBox->DoEnable();
  725.                 SpecificSpeedText->DoEnable();
  726.                 if (SpecificSpeedBox->GetValue() != Temp.Speed)
  727.                     {
  728.                         SpecificSpeedBox->SetValue(Temp.Speed);
  729.                     }
  730.             }
  731.          else
  732.             {
  733.                 SpecificSpeedBox->DoDisable();
  734.                 SpecificSpeedText->DoDisable();
  735.                 if (Selection == Playing)
  736.                     {
  737.                         SendMessage((short)Speed,keySpeed);
  738.                     }
  739.             }
  740.         ListOfSongs->PutElement(Selection,&Temp);
  741.     }
  742.  
  743.  
  744. void                CMyDocument::SetOverrideVolume(MyBoolean Flag)
  745.     {
  746.         SongRec                Temp;
  747.  
  748.         if (Selection == -1)
  749.             {
  750.                 return;
  751.             }
  752.  
  753.         UpToDate = False;
  754.         ListOfSongs->GetElement(Selection,&Temp);
  755.         Temp.VolumeOverrideDefault = Flag;
  756.         if (Flag)
  757.             {
  758.                 Temp.Volume = Volume;
  759.                 SpecificVolumeBox->DoEnable();
  760.                 SpecificVolumeText->DoEnable();
  761.                 if (SpecificVolumeBox->GetValue() != Temp.Volume)
  762.                     {
  763.                         SpecificVolumeBox->SetValue(Temp.Volume);
  764.                     }
  765.             }
  766.          else
  767.             {
  768.                 SpecificVolumeBox->DoDisable();
  769.                 SpecificVolumeText->DoDisable();
  770.                 if (Selection == Playing)
  771.                     {
  772.                         SendMessage((short)Volume,keyLoudness);
  773.                     }
  774.             }
  775.         ListOfSongs->PutElement(Selection,&Temp);
  776.     }
  777.  
  778.  
  779. void                CMyDocument::SetDefaultStereoOn(MyBoolean NewStereoOn)
  780.     {
  781.         StereoOn = NewStereoOn;
  782.         if (DefaultStereoOnBox->State != NewStereoOn)
  783.             {
  784.                 DefaultStereoOnBox->DoThang();
  785.             }
  786.         if (!OverrideStereoOnBox->State)
  787.             {
  788.                 if (SpecificStereoOnBox->State != NewStereoOn)
  789.                     {
  790.                         SpecificStereoOnBox->DoThang();
  791.                     }
  792.                 if (Selection == Playing)
  793.                     {
  794.                         SendMessage((short)NewStereoOn,keyStereoOn);
  795.                     }
  796.             }
  797.         UpToDate = False;
  798.     }
  799.  
  800.  
  801. void                CMyDocument::SetDefaultAntiAliasing(MyBoolean NewAntiAliasing)
  802.     {
  803.         AntiAliasing = NewAntiAliasing;
  804.         if (DefaultAntiAliasingBox->State != NewAntiAliasing)
  805.             {
  806.                 DefaultAntiAliasingBox->DoThang();
  807.             }
  808.         if (!OverrideAntiAliasingBox->State)
  809.             {
  810.                 if (SpecificAntiAliasingBox->State != NewAntiAliasing)
  811.                     {
  812.                         SpecificAntiAliasingBox->DoThang();
  813.                     }
  814.                 if (Selection == Playing)
  815.                     {
  816.                         SendMessage((short)NewAntiAliasing,keyAntiAliasing);
  817.                     }
  818.             }
  819.         UpToDate = False;
  820.     }
  821.  
  822.  
  823. void                CMyDocument::SetDefaultSamplingRate(ulong NewSamplingRate)
  824.     {
  825.         SamplingRate = NewSamplingRate;
  826.         if (DefaultSamplingRateBox->GetValue() != NewSamplingRate)
  827.             {
  828.                 DefaultSamplingRateBox->SetValue(NewSamplingRate);
  829.             }
  830.         if (!OverrideSamplingRateBox->State)
  831.             {
  832.                 if (SpecificSamplingRateBox->GetValue() != NewSamplingRate)
  833.                     {
  834.                         SpecificSamplingRateBox->SetValue(NewSamplingRaheFile.name);
  835.                 RegisterString(String1);
  836.                 String2 = GetCString(SeparatorID);
  837.                 RegisterString(String2);
  838.                 String3 = PString2Handle(TheSong.SongName);
  839.                 RegisterString(String3);
  840.                 String1 = ConStr(String1,String2);
  841.                 String1 = ConStr(String1,String3);
  842.                 EndStringOperation(String1);
  843.                 Handle2PString(String1,NewWindowName);
  844.                 ReleaseHandle(String1);
  845.                 SetWTitle(RootWindow->MyGrafPtr,NewWindowName);
  846.  
  847.                 /* constructing nasty parameter block & sending open event to tracker */
  848.                 HLock((Handle)this);
  849.  
  850.                 Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPlayer,
  851.                     sizeof(ProcessSerialNumber),&AddressDescriptor);
  852.  
  853.                 Error = AECreateAppleEvent(kCoreEventClass,kAEOpenDocuments,&AddressDescriptor,
  854.                     kAutoGenerateReturnID,kAnyTransactionID,&Event);
  855.                 CheckHeap();
  856.  
  857.                 Error = AECreateList(NIL,0,False,&FileList);
  858.                 HLock((Handle)TheSong.SongLocation);
  859.                 AECreateDesc(typeAlias,(void*)*TheSong.SongLocation,
  860.                     HandleSize((Handle)TheSong.SongLocation),&ListElement);
  861.                 HUnlock((Handle)TheSong.SongLocation);
  862.                 Error = AEPutDesc(&FileList,0,&ListElement);
  863.                 Error = AEDisposeDesc(&ListElement);
  864.                 Error = AEPutParamDesc(&Event,keyDirectObject,&FileList);
  865.                 Error = AEDisposeDesc(&FileList);
  866.  
  867.                 if (TheSong.AntiAliasingOverrideDefault)
  868.                     {
  869.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.AntiAliasing,
  870.                             sizeof(MyBoolean),&TempDesc);
  871.                     }
  872.                  else
  873.                     {
  874.                         Error = AECreateDesc(typeShortInteger,(void*)&AntiAliasing,
  875.                             sizeof(MyBoolean),&TempDesc);
  876.                     }
  877.                 Error = AEPutParamDesc(&Event,keyAntiAliasing,&TempDesc);
  878.                 Error = AEDisposeDesc(&TempDesc);
  879.  
  880.                 if (TheSong.StereoOnOverrideDefault)
  881.                     {
  882.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.StereoOn,
  883.                             sizeof(MyBoolean),&TempDesc);
  884.                     }
  885.                  else
  886.                     {
  887.                         Error = AECreateDesc(typeShortInteger,(void*)&StereoOn,
  888.                             sizeof(MyBoolean),&TempDesc);
  889.                     }
  890.                 Error = AEPutParamDesc(&Event,keyStereoOn,&TempDesc);
  891.                 Error = AEDisposeDesc(&TempDesc);
  892.  
  893.                 if (TheSong.SamplingRateOverrideDefault)
  894.                     {
  895.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.SamplingRate,
  896.                             sizeof(ushort),&TempDesc);
  897.                     }
  898.                  else
  899.                     {
  900.                         Error = AECreateDesc(typeShortInteger,(void*)&SamplingRate,
  901.                             sizeof(ushort),&TempDesc);
  902.                     }
  903.                 Error = AEPutParamDesc(&Event,keySamplingRate,&TempDesc);
  904.                 Error = AEDisposeDesc(&TempDesc);
  905.  
  906.                 if (TheSong.NumRepeatsOverrideDefault)
  907.                     {
  908.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.NumRepeats,
  909.                             sizeof(short),&TempDesc);
  910.                     }
  911.                  else
  912.                     {
  913.                         Error = AECreateDesc(typeShortInteger,(void*)&NumRepeats,
  914.                             sizeof(short),&TempDesc);
  915.                     }
  916.                 Error = AEPutParamDesc(&Event,keyNumRepeats,&TempDesc);
  917.                 Error = AEDisposeDesc(&TempDesc);
  918.  
  919.                 if (TheSong.SpeedOverrideDefault)
  920.                     {
  921.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.Speed,
  922.                             sizeof(short),&TempDesc);
  923.                     }
  924.                  else
  925.                     {
  926.                         Error = AECreateDesc(typeShortInteger,(void*)&Speed,
  927.                             sizeof(short),&TempDesc);
  928.                     }
  929.                 Error = AEPutParamDesc(&Event,keySpeed,&TempDesc);
  930.                 Error = AEDisposeDesc(&TempDesc);
  931.  
  932.                 if (TheSong.StereoMixOverrideDefault)
  933.                     {
  934.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.StereoMix,
  935.                             sizeof(short),&TempDesc);
  936.                     }
  937.                  else
  938.                     {
  939.                         Error = AECreateDesc(typeShortInteger,(void*)&StereoMix,
  940.                             sizeof(short),&TempDesc);
  941.                     }
  942.                 Error = AEPutParamDesc(&Event,keyStereoMix,&TempDesc);
  943.                 Error = AEDisposeDesc(&TempDesc);
  944.  
  945.                 if (TheSong.VolumeOverrideDefault)
  946.                     {
  947.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.Volume,
  948.                             sizeof(short),&TempDesc);
  949.                     }
  950.                  else
  951.                     {
  952.                         Error = AECreateDesc(typeShortInteger,(void*)&Volume,
  953.                             sizeof(short),&TempDesc);
  954.                     }
  955.                 Error = AEPutParamDesc(&Event,keyLoudness,&TempDesc);
  956.                 Error = AEDisposeDesc(&TempDesc);
  957.  
  958.                 if (UseSixteenBitMode)
  959.                     {
  960.                         BitTemp = 16;
  961.                     }
  962.                  else
  963.                     {
  964.                         BitTemp = 8;
  965.                     }
  966.                 Error = AECreateDesc(typeShortInteger,(void*)&BitTemp,
  967.                     sizeof(short),&TempDesc);
  968.                 Error = AEPutParamDesc(&Event,keyNumBits,&TempDesc);
  969.                 Error = AEDisposeDesc(&TempDesc);
  970.  
  971.                 Error = GetCurrentProcess(&OurPSN);
  972.                 Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPSN,
  973.                     sizeof(ProcessSerialNumber),&TempDesc);
  974.                 Error = AEPutParamDesc(&Event,keySenderPSN,&TempDesc);
  975.                 Error = AEDisposeDesc(&TempDesc);
  976.  
  977.                 Application->SendMessage(OurPlayer,&Event);
  978.                 Error = AEDisposeDesc(&AddressDescriptor);
  979.                 Error = AEDisposeDesc(&Event);
  980.                 HUnlock((Handle)this);
  981.  
  982.                 if (PausePlayButton != NIL)
  983.                     {
  984.                         delete PausePlayButton;
  985.                     }
  986.                 PauseButton = new CPauseButton;
  987.                 PausePlayButton = PauseButton;
  988.                 PauseButton->IPauseButton(this,RootWindow);
  989.                 if (!RootWindow->Suspended)
  990.                     {
  991.                         PauseButton->DoResume();
  992.                     }
  993.                 PauseButton->DoUpdate();
  994.  
  995.                 StopButton->DoEnable();
  996.                 RewindButton->DoEnable();
  997.                 FastForwardButton->DoEnable();
  998.                 SkipToNextButton->DoEnable();
  999.             }
  1000.     }
  1001.  
  1002.  
  1003. void                CMyDocument::PlayerDiedNotification(void)
  1004.     {
  1005.         CPlayButton*        PlayButton;
  1006.         long                        OldPlayer;
  1007.  
  1008.         PlayerExists = False;
  1009.         OldPlayer = Playing;
  1010.         Playing = -1;
  1011.         HLock((Handle)this);
  1012.         SetWTitle(RootWindow->MyGrafPtr,TheFile.name);
  1013.         HUnlock((Handle)this);
  1014.         SongList->Redraw(OldPlayer,OldPlayer);
  1015.         if (PlayNextWhenThisOneStops)
  1016.             {
  1017.                 if (SongToStart == -1)
  1018.                     {
  1019.                         /* we want to hear the "next" song, but one was not specified. */
  1020.                         if (Randomize)
  1021.                             {
  1022.                                 StartRandomSong();
  1023.                             }
  1024.                          else
  1025.                             {
  1026.                                 if (OldPlayer < ListOfSongs->GetNumElements() - 1)
  1027.                                     {
  1028.                                         StartThisSong(OldPlayer + 1);
  1029.                                     }
  1030.                                  else
  1031.                                     {
  1032.                                         if (Repeat)
  1033.                                             {
  1034.                                                 StartThisSong(0);
  1035.                                             }
  1036.                                          else
  1037.                                             {
  1038.                                                 PlayNextWhenThisOneStops = False;
  1039.                                             }
  1040.                                     }
  1041.                             }
  1042.                     }
  1043.                  else
  1044.                     {
  1045.                         /* they DID specify which song to listen to next */
  1046.                         StartThisSong(SongToStart);
  1047.                     }
  1048.             }
  1049.  
  1050.         delete PausePlayButton;
  1051.         PlayButton = new CPlayButton;
  1052.         PlayButton->IPlayButton(this,RootWindow);
  1053.         PausePlayButton = PlayButton;
  1054.         if (!RootWindow->Suspended)
  1055.             {
  1056.                 PlayButton->DoResume();
  1057.             }
  1058.         PlayButton->DoUpdate();
  1059.  
  1060.         StopButton->DoDisable();
  1061.         RewindButton->DoDisable();
  1062.         FastForwardButton->DoDisable();
  1063.         SkipToNextButton->DoDisable();
  1064.     }
  1065.  
  1066.  
  1067. void                CMyDocument::PlayerLaunchedNotification(ProcessSerialNumber TheProcNum)
  1068.     {
  1069.         StackSizeTest();
  1070.         PlayerExists = True;
  1071.         PlayerState = PlayerWaitingForInit;
  1072.         OurPlayer = TheProcNum;
  1073.     }
  1074.  
  1075.  
  1076. void                CMyDocument::SetNewSelection(long NewSelection)
  1077.     {
  1078.         SpecificSamplingRateBox->StoreValue();
  1079.         SpecificStereoMixBox->StoreValue();
  1080.         SpecificNumRepeatsBox->StoreValue();
  1081.         SpecificSpeedBox->StoreValue();
  1082.         SpecificVolumeBox->StoreValue();
  1083.         DefaultSamplingRateBox->StoreValue();
  1084.         DefaultStereoMixBox->StoreValue();
  1085.         DefaultNumRepeatsBox->StoreValue();
  1086.         DefaultSpeedBox->StoreValue();
  1087.         DefaultVolumeBox->StoreValue();
  1088.         if (Selection != -1)
  1089.             {
  1090.                 long            SelectionTemp;
  1091.  
  1092.                 SelectionTemp = Selection;
  1093.                 Selection = -1;
  1094.                 SongList->Redraw(SelectionTemp,SelectionTemp);
  1095.             }
  1096.         Selection = NewSelection;
  1097.         if (NewSelection == -1)
  1098.             {
  1099.                 CStaticText*        StaticText;
  1100.                 LongPoint                Start,Extent;
  1101.  
  1102.                 SpecificStereoOnBox->DoDisable();
  1103.                 SpecificAntiAliasingBox->DoDisable();
  1104.                 SpecificSamplingRateBox->DoDisable();
  1105.                 SpecificStereoMixBox->DoDisable();
  1106.                 SpecificNumRepeatsBox->DoDisable();
  1107.                 SpecificSpeedBox->DoDisable();
  1108.                 SpecificVolumeBox->DoDisable();
  1109.                 SpecificSamplingRateText->DoDisable();
  1110.                 SpecificStereoMixText->DoDisable();
  1111.                 SpecificNumRepeatsText->DoDisable();
  1112.                 SpecificSpeedText->DoDisable();
  1113.                 SpecificVolumeText->DoDisable();
  1114.                 OverrideStereoOnBox->DoDisable();
  1115.                 OverrideAntiAliasingBox->DoDisable();
  1116.                 OverrideSamplingRateBox->DoDisable();
  1117.                 OverrideStereoMixBox->DoDisable();
  1118.                 OverrideNumRepeatsBox->DoDisable();
  1119.                 OverrideSpeedBox->DoDisable();
  1120.                 OverrideVolumeBox->DoDisable();
  1121.             }
  1122.          else
  1123.             {
  1124.                 LongPoint            Start,Extent;
  1125.                 Handle                String1;
  1126.                 Handle                String2;
  1127.                 Handle                String3;
  1128.                 Handle                String4;
  1129.                 SongRec                TheSong;
  1130.                 CPauseButton*    PauseButton;
  1131.                 CStaticText*    StaticText;
  1132.  
  1133.                 StackSizeTest();
  1134.                 SongList->Redraw(NewSelection,NewSelection);
  1135.                 ListOfSongs->GetElement(NewSelection,&TheSong);
  1136.  
  1137.                 OverrideStereoOnBox->DoEnable();
  1138.                 if (OverrideStereoOnBox->State != TheSong.StereoOnOverrideDefault)
  1139.                     {
  1140.                         OverrideStereoOnBox->DoThang();
  1141.                     }
  1142.                 if (TheSong.StereoOnOverrideDefault)
  1143.                     {
  1144.                         SpecificStereoOnBox->DoEnable();
  1145.                         if (SpecificStereoOnBox->State != TheSong.StereoOn)
  1146.                             {
  1147.                                 SpecificStereoOnBox->DoThang();
  1148.                             }
  1149.                     }
  1150.                  else
  1151.                     {
  1152.                         SpecificStereoOnBox->DoDisable();
  1153.                     }
  1154.  
  1155.                 OverrideAntiAliasingBox->DoEnable();
  1156.                 if (OverrideAntiAliasingBox->State != TheSong.AntiAliasingOverrideDefault)
  1157.                     {
  1158.                         OverrideAntiAliasingBox->DoThang();
  1159.                     }
  1160.                 if (TheSong.AntiAliasingOverrideDefault)
  1161.                     {
  1162.                         SpecificAntiAliasingBox->DoEnable();
  1163.                         if (SpecificAntiAliasingBox->State != TheSong.AntiAliasing)
  1164.                             {
  1165.                                 SpecificAntiAliasingBox->DoThang();
  1166.                             }
  1167.                     }
  1168.                  else
  1169.                     {
  1170.                         SpecificAntiAliasingBox->DoDisable();
  1171.                     }
  1172.  
  1173.                 OverrideSamplingRateBox->DoEnable();
  1174.                 if (OverrideSamplingRateBox->State != TheSong.SamplingRateOverrideDefault)
  1175.                     {
  1176.                         OverrideSamplingRateBox->DoThang();
  1177.                     }
  1178.                 if (TheSong.SamplingRateOverrideDefault)
  1179.                     {
  1180.                         SpecificSamplingRateBox->DoEnable();
  1181.                         SpecificSamplingRateText->DoEnable();
  1182.                         SpecificSamplingRateBox->SetValue(TheSong.SamplingRate);
  1183.                     }
  1184.                  else
  1185.                     {
  1186.                         SpecificSamplingRateBox->DoDisable();
  1187.                         SpecificSamplingRateText->DoDisable();
  1188.                     }
  1189.  
  1190.                 OverrideStereoMixBox->DoEnable();
  1191.                 if (OverrideStereoMixBox->State != TheSong.StereoMixOverrideDefault)
  1192.                     {
  1193.                         OverrideStereoMixBox->DoThang();
  1194.                     }
  1195.                 if (TheSong.StereoMixOverrideDefault)
  1196.                     {
  1197.                         SpecificStereoMixBox->DoEnable();
  1198.                         SpecificStereoMixText->DoEnable();
  1199.                         SpecificStereoMixBox->SetValue(TheSong.StereoMix);
  1200.                     }
  1201.                  else
  1202.                     {
  1203.                         SpecificStereoMixBox->DoDisable();
  1204.                         SpecificStereoMixText->DoDisable();
  1205.                     }
  1206.  
  1207.                 OverrideNumRepeatsBox->DoEnable();
  1208.                 if (OverrideNumRepeatsBox->State != TheSong.NumRepeatsOverrideDefault)
  1209.                     {
  1210.                         OverrideNumRepeatsBox->DoThang();
  1211.                     }
  1212.                 if (TheSong.NumRepeatsOverrideDefault)
  1213.                     {
  1214.                         SpecificNumRepeatsBox->DoEnable();
  1215.                         SpecificNumRepeatsText->DoEnable();
  1216.                         SpecificNumRepeatsBox->SetValue(TheSong.NumRepeats);
  1217.                     }
  1218.                  else
  1219.                     {
  1220.                         SpecificNumRepeatsBox->DoDisable();
  1221.                         SpecificNumRepeatsText->DoDisable();
  1222.                     }
  1223.  
  1224.                 OverrideSpeedBox->DoEnable();
  1225.                 if (OverrideSpeedBox->State != TheSong.SpeedOverrideDefault)
  1226.                     {
  1227.                         OverrideSpeedBox->DoThang();
  1228.                     }
  1229.                 if (TheSong.SpeedOverrideDefault)
  1230.                     {
  1231.                         SpecificSpeedBox->DoEnable();
  1232.                         SpecificSpeedText->DoEnable();
  1233.                         SpecificSpeedBox->SetValue(TheSong.Speed);
  1234.                     }
  1235.                  else
  1236.                     {
  1237.                         SpecificSpeedBox->DoDisable();
  1238.                         SpecificSpeedText->DoDisable();
  1239.                     }
  1240.  
  1241.                 OverrideVolumeBox->DoEnable();
  1242.                 if (OverrideVolumeBox->State != TheSong.VolumeOverrideDefault)
  1243.                     {
  1244.                         OverrideVolumeBox->DoThang();
  1245.                     }
  1246.                 if (TheSong.VolumeOverrideDefault)
  1247.                     {
  1248.                         SpecificVolumeBox->DoEnable();
  1249.                         SpecificVolumeText->DoEnable();
  1250.                         SpecificVolumeBox->SetValue(TheSong.Volume);
  1251.                     }
  1252.                  else
  1253.                     {
  1254.                         SpecificVolumeBox->DoDisable();
  1255.                         SpecificVolumeText->DoDisable();
  1256.                     }
  1257.             }
  1258.     }
  1259.  
  1260.  
  1261. void                CMyDocument::MoveSong(long SongIndex, long NewIndex)
  1262.     {
  1263.         SongRec            MySong;
  1264.         long                OldSelection;
  1265.         long                Temp;
  1266.  
  1267.         UpToDate = False;
  1268.         SpecificSamplingRateBox->StoreValue();
  1269.         SpecificStereoMixBox->StoreValue();
  1270.         SpecificNumRepeatsBox->StoreValue();
  1271.         SpecificSpeedBox->StoreValue();
  1272.         SpecificVolumeBox->StoreValue();
  1273.         DefaultSamplingRateBox->StoreValue();
  1274.         DefaultStereoMixBox->StoreValue();
  1275.         DefaultNumRepeatsBox->StoreValue();
  1276.         DefaultSpeedBox->StoreValue();
  1277.         DefaultVolumeBox->StoreValue();
  1278.  
  1279.         OldSelection = Playing;
  1280.         Playing = -1;
  1281.         SongList->Redraw(OldSelection,OldSelection);
  1282.         Playing = OldSelection;
  1283.         if (Playing == SongIndex)
  1284.             {
  1285.                 Playing = NewIndex;
  1286.                 if (NewIndex > SongIndex)
  1287.                     {
  1288.                         Playing -= 1;
  1289.                     }
  1290.             }
  1291.          else
  1292.             {
  1293.                 if (SongIndex < NewIndex)
  1294.                     {
  1295.                         if ((Playing > SongIndex) && (Playing < NewIndex))
  1296.                             {
  1297.                                 Playing -= 1;
  1298.                             }
  1299.                     }
  1300.                  else
  1301.                     {
  1302.                         if ((Playing >= NewIndex) && (Playing < SongIndex))
  1303.                             {
  1304.                                 Playing += 1;
  1305.                             }
  1306.                     }
  1307.             }
  1308.         SongList->Redraw(Playing,Playing);
  1309.  
  1310.         OldSelection = Selection;
  1311.         Selection = -1;
  1312.         SongList->Redraw(OldSelection,OldSelection);
  1313.         if ((SongIndex < 0) || (SongIndex >= ListOfSongs->GetNumElements()))
  1314.             {
  1315.                 return;
  1316.             }
  1317.         if (NewIndex < 0)
  1318.             {
  1319.                 NewIndex = 0;
  1320.             }
  1321.         ListOfSongs->GetElement(SongIndex,&MySong);
  1322.         ListOfSongs->DeleteElement(SongIndex);
  1323.         if (NewIndex > SongIndex)
  1324.             {
  1325.                 NewIndex -= 1;
  1326.             }
  1327.         NewIndex = ListOfSongs->InsertElement(NewIndex);
  1328.         ListOfSongs->PutElement(NewIndex,&MySong);
  1329.         Selection = NewIndex;
  1330.         if (SongIndex > NewIndex)
  1331.             {
  1332.                 Temp = SongIndex;
  1333.                 SongIndex = NewIndex;
  1334.                 NewIndex = Temp;
  1335.             }
  1336.         SongList->Redraw(SongIndex,NewIndex);
  1337.     }
  1338.  
  1339.  
  1340. void                CMyDocument::ResetRandomPlayList(void)
  1341.     {
  1342.         long                Scan;
  1343.         long                End;
  1344.         SongRec            Temp;
  1345.  
  1346.         End = ListOfSongs->GetNumElements();
  1347.         for (Scan = 0; Scan < End; Scan += 1)
  1348.             {
  1349.                 ListOfSongs->GetElement(Scan,&Temp);
  1350.                 Temp.PlayedFlag = False;
  1351.                 ListOfSongs->PutElement(Scan,&Temp);
  1352.             }
  1353.     }
  1354.  
  1355.  
  1356. void                CMyDocument::StartRandomSong(void)
  1357.     {
  1358.         short                RunoutCount;
  1359.         long                Possibility;
  1360.         long                NumSongs;
  1361.         SongRec            Temp;
  1362.         long                StartingPoint;
  1363.  
  1364.         /* randomly look for a song that hasn't been played.  If we */
  1365.         /* can't find one then do a linear search for one.  If we fail that */
  1366.         /* then there are no more: reset and play if <repeat> is on, otherwise */
  1367.         /* just stop. */
  1368.         CancelCurrentSong();
  1369.      TryAgainPoint:
  1370.         NumSongs = ListOfSongs->GetNumElements();
  1371.         if (NumSongs == 0)
  1372.             {
  1373.                 return; /* oops, can't play anything */
  1374.             }
  1375.         RunoutCount = MAXRANDOMTRIESBEFOREGIVINGUP;
  1376.         while (RunoutCount > 0)
  1377.             {
  1378.                 Possibility = ((unsigned short)Random()) % NumSongs;
  1379.                 ListOfSongs->GetElement(Possibility,&Temp);
  1380.                 if (!Temp.PlayedFlag)
  1381.                     {
  1382.                         /* found one to play */
  1383.                      FoundOnePoint:
  1384.                         StartThisSong(Possibility);
  1385.                         return;
  1386.                     }
  1387.                 RunoutCount -= 1;
  1388.             }
  1389.         /* failed random search.  Do linear search */
  1390.         StartingPoint = Possibility;
  1391.         do
  1392.             {
  1393.                 Possibility += 1;
  1394.                 if (Possibility >= NumSongs)
  1395.                     {
  1396.                         Possibility = 0;
  1397.                     }
  1398.                 ListOfSongs->GetElement(Possibility,&Temp);
  1399.                 if (!Temp.PlayedFlag)
  1400.                     {
  1401.                         goto FoundOnePoint;
  1402.                     }
  1403.             } while (Possibility != StartingPoint);
  1404.         /* failed that!  Reset and try again. */
  1405.         if (Repeat)
  1406.             {
  1407.                 /* there is no possible way to get into an infinite loop. */
  1408.                 ResetRandomPlayList();
  1409.                 goto TryAgainPoint;
  1410.             }
  1411.     }
  1412.  
  1413.  
  1414. /* this sends control events to the remote player.  Note that it only */
  1415. /* supports short integer messages, but that's ok because they're all shorts */
  1416. void                CMyDocument::SendMessage(short TheMessage, DescType TheKeyWord)
  1417.     {
  1418.         short                        Error;
  1419.         AppleEvent            Event;
  1420.         AEAddressDesc        AddressDescriptor;
  1421.         short                        KeyPress;
  1422.  
  1423.         HLock((Handle)this); /* make sure the OurPlayer variable doesn't move */
  1424.         Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPlayer,
  1425.             sizeof(ProcessSerialNumber),&AddressDescriptor);
  1426.         HUnlock((Handle)this);
  1427.         Error = AECreateAppleEvent(ControlEventClass,ControlEvent,&AddressDescriptor,
  1428.             kAutoGenerateReturnID,kAnyTransactionID,&Event);
  1429.         Error = AEPutParamPtr(&Event,TheKeyWord,typeShortInteger,
  1430.             (void*)&TheMessage,sizeof(short));
  1431.         Application->SendMessage(OurPlayer,&Event);
  1432.         Error = AEDisposeDesc(&AddressDescriptor);
  1433.         Error = AEDisposeDesc(&Event);
  1434.         HUnlock((Handle)this);
  1435.     }
  1436.